<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

<script>



// 7.substr(start,length)用于截取字符串
// start 截取的起始位置
// length 截取字符串的个数
var str1 = 'abc123def456';
console.log( str1.substr(3,3) );// '123'
console.log( str1.substr(1,5) );// 'bc123'
console.log( str1.substr(3) );// '123def456'
console.log( str1.substr() );// 'abc123def456'
console.log( str1.substr(1) );// 'bc123def456'
console.log( str1.substr(0,str1.length-1) );// 'abc123def45'


// 8.substring(start,end)用于截取字符串
// start 截取的起始位置
// end 截取的结束位置（不含结束位置的字符）
// var str2 = 'abc123def456';
console.log( str2.substring(3,3) );// ''
console.log( str2.substring(1,5) );// 'bc12'
console.log( str2.substring(3) );// '123def456'
console.log( str2.substring() );// 'abc123def456'
console.log( str2.substring(1) );// 'bc123def456'
console.log( str2.substring(0,str2.length-1) );// 'abc123def45'


// 9.slice(start,end)用于截取字符串
// start 截取的起始位置
// end 截取的结束位置（不含结束位置的字符）
var str3 = 'abc123def456';
console.log( str3.slice(3,3) );// ''
console.log( str3.slice(1,5) );// 'bc12'
console.log( str3.slice(3) );// '123def456'
console.log( str3.slice() );// 'abc123def456'
console.log( str3.slice(3,-3) );// '123def'  -3倒数第三个字符
console.log( str3.slice(-1,-3) );// '' 起始位置为负数 返回空字符


// 10.split(分割符)分割字符串，返回数组
// var str4 = 'sid=123&wd=hehe&cb=test';
// console.log( str4.split() );// ['sid=123&wd=hehe&cb=test']
// console.log( str4.split('') );// ['s', 'i', 'd', '=', '1', '2', '3', '&', 'w', 'd', '=', 'h', 'e', 'h', 'e', '&', 'c', 'b', '=', 't', 'e', 's', 't']
// console.log( str4.split('&') );// ['sid=123','wd=hehe','cb=test']
// console.log( str4.split('&',2) );// ['sid=123','wd=hehe']  2表示返回数组的长度


// 11.concat()用于合并字符串
// var str1 = 'hello ';
// var str2 = 'world';
// console.log( str1.concat(str2) );// 'hello world'
// console.log( str1 + str2 );// 'hello world'


// 12.charAt(index)返回指定索引位置的字符
// var str3 = 'abcdef';
// console.log( str3.charAt(3) );// 'd'
// console.log( str3[3] );// 'd'


// 13.replace(str1,str2)使用str2替换str1，返回替换后的字符串
var str4 = '严海静真英俊';
console.log( str4.replace('严海静','老陶') );

var str5 = '马化腾真有钱。。。';
console.log( str5.replace('马化腾','***') );

</script>
</body>
</html>